﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLyShop.BUS;
using DevComponents.DotNetBar;

namespace SHOP
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
            
            
        }
         private bool checkTab(string name)
        {
            for (int i = 0; i < spTabControl.Tabs.Count; i++)
            {
                if (spTabControl.Tabs[i].Text == name)
                {
                    spTabControl.SelectedTabIndex = i;
                    return true;
                }
            }
            return false;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            //taskbartime.Text = System.DateTime.Now.ToString();
        }

        private void buttonItem12_Click(object sender, EventArgs e)
        {
            if (checkTab("Giỏ Hàng") == false)
            {
                SuperTabItem tab = spTabControl.CreateTab("Giỏ Hàng");
                BH_GioHang bh_GioHang = new BH_GioHang();
                bh_GioHang.Dock = DockStyle.Fill;
                bh_GioHang.FormBorderStyle = FormBorderStyle.None;
                bh_GioHang.TopLevel = false;
                tab.AttachedControl.Controls.Add(bh_GioHang);
                bh_GioHang.Show();
                bh_GioHang.myGetData = new BH_GioHang.getString(getValue);
                
            }
        }

        private void buttonItem14_Click(object sender, EventArgs e)
        {
           
            if (checkTab("Hóa Đơn Bán Hàng") == false)
            {
                SuperTabItem tab = spTabControl.CreateTab("Hóa Đơn Bán Hàng");
                BH_QL_HoaDonBan qlHoaDonBan = new BH_QL_HoaDonBan();
                qlHoaDonBan.Dock = DockStyle.Fill;
                qlHoaDonBan.FormBorderStyle = FormBorderStyle.None;
                qlHoaDonBan.TopLevel = false;
                tab.AttachedControl.Controls.Add(qlHoaDonBan);
                qlHoaDonBan.Show();
                
            }
        }
        private void ribbonControl1_Click(object sender, EventArgs e)
        {
            SanPhamBUS Bus = new SanPhamBUS();
            DataTable dt = new DataTable();
            dgv_SanPham.DataSource = dt;
        }

        private void Main_Load(object sender, EventArgs e)
        {
            SanPhamBUS Bus = new SanPhamBUS();
            TinhTrangBaoHanhBUS tt = new TinhTrangBaoHanhBUS();
            DataTable dt = new DataTable();
            dt = Bus.LayDanhSachSanPham();
            dgv_SanPham.DataSource = dt;
        }

        private void chọnMuaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChonMua frmChonMua = new ChonMua();
            frmChonMua.ShowDialog();
        }

        private void chiTiếtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BH_ChiTietSP frmChiTiet = new BH_ChiTietSP();
            frmChiTiet.ShowDialog();
        }

        private void btnBaoHanh_Click(object sender, EventArgs e)
        {

            if (checkTab("Các Sản Phẩm Trong Diện Bảo Hành") == false)
            {
                SuperTabItem tab = spTabControl.CreateTab("Các Sản Phẩm Trong Diện Bảo Hành");
                BH_QL_BaoHanh qlHoaDonBan = new BH_QL_BaoHanh();
                qlHoaDonBan.Dock = DockStyle.Fill;
                qlHoaDonBan.FormBorderStyle = FormBorderStyle.None;
                qlHoaDonBan.TopLevel = false;
                tab.AttachedControl.Controls.Add(qlHoaDonBan);
                qlHoaDonBan.Show();
            }
            
        }

        // phan nhap hang

        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            NH_NhapThemSPMoi frmThemSanPham = new NH_NhapThemSPMoi();
            frmThemSanPham.Show();
        }

        private void btnQLNhapHang_Click(object sender, EventArgs e)
        {
            if (checkTab("Các Đơn Hàng Đã Nhập") == false)
            {
                SuperTabItem tab = spTabControl.CreateTab("Các Đơn Hàng Đã Nhập");
                NH_QuanLyNhapHang qlDonNhapHang = new NH_QuanLyNhapHang();
                qlDonNhapHang.Dock = DockStyle.Fill;
                qlDonNhapHang.FormBorderStyle = FormBorderStyle.None;
                qlDonNhapHang.TopLevel = false;
                tab.AttachedControl.Controls.Add(qlDonNhapHang);
                qlDonNhapHang.Show();
                qlDonNhapHang.myGetData = new NH_QuanLyNhapHang.getString(getValue);
            }
        }

        // delegate

        public void getValue(String strInput1, String strInput2)
        {
            if (strInput1 == "closetab" && strInput2 == "createtab")
            {
                int index = spTabControl.TabIndex;
                spTabControl.Tabs.RemoveAt(index);
                if (checkTab("Thanh Toán") == false)
                {
                    SuperTabItem tab = spTabControl.CreateTab("Thanh Toán");
                    BH_ThanhToan bhThanhToan = new BH_ThanhToan();
                    bhThanhToan.Dock = DockStyle.Fill;
                    bhThanhToan.FormBorderStyle = FormBorderStyle.None;
                    bhThanhToan.TopLevel = false;
                    tab.AttachedControl.Controls.Add(bhThanhToan);
                    bhThanhToan.Show();
                }
            }
            else if (strInput1 == "" && strInput2 == "Open Chi Tiet Don Hang")
            {
                if (checkTab("Chi Tiết Đơn Nhập Hàng") == false)
                {
                    SuperTabItem tab = spTabControl.CreateTab("Chi Tiết Đơn Nhập Hàng");
                    NH_ChiTietDonNhapHang bhChiTietDonNhapHang = new NH_ChiTietDonNhapHang();
                    bhChiTietDonNhapHang.Dock = DockStyle.Fill;
                    bhChiTietDonNhapHang.FormBorderStyle = FormBorderStyle.None;
                    bhChiTietDonNhapHang.TopLevel = false;
                    tab.AttachedControl.Controls.Add(bhChiTietDonNhapHang);
                    bhChiTietDonNhapHang.Show();
                }
            }
        }

        private void buttonItem26_Click(object sender, EventArgs e)
        {
            TL_GiaBan tlGiaBan = new TL_GiaBan();
            tlGiaBan.ShowDialog();
        }

        private void buttonItem27_Click(object sender, EventArgs e)
        {
            TL_BaoHanh frmBaoHanh = new TL_BaoHanh();
            frmBaoHanh.ShowDialog();
        }

        private void buttonItem16_Click(object sender, EventArgs e)
        {
            TL_QL_DanhMuc frmQuanLyDanhMuc = new TL_QL_DanhMuc();
            frmQuanLyDanhMuc.ShowDialog();
        }
    }
}
